package com.doitedu.doit30.hbase.filter;

import com.doitedu.doit30.hbase.utils.HbaseUtil;
import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.BinaryComparator;
import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.filter.QualifierFilter;
import org.apache.hadoop.hbase.filter.ValueFilter;

/**
 * @Date 22.6.12
 * @Created by HANGGE
 * @Description
 *   uid  = 1
 */
public class Demo02 {
    public static void main(String[] args)  throws  Exception{
        Connection conn = HbaseUtil.getHbaseConnection();
        Table tb_movie = HbaseUtil.getTable(conn, "tb_movie");

        Scan scan = new Scan();

        QualifierFilter qualifierFilter = new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator("uid".getBytes()));
        ValueFilter valueFilter = new ValueFilter(CompareOperator.EQUAL, new BinaryComparator("1".getBytes()));
    /*    scan.setFilter(qualifierFilter);
        scan.setFilter(valueFilter) ;*/

        FilterList filterList = new FilterList(); // 将过个过滤器串联
        filterList.addFilter(qualifierFilter);
        filterList.addFilter(valueFilter);
        scan.setFilter(filterList);

        ResultScanner scanner = tb_movie.getScanner(scan);
        for (Result result : scanner) {
            HbaseUtil.showData(result);
        }
        conn.close();
        tb_movie.close();
    }


}
